package ace.module.oss.core.autoconfig;

import ace.cmp.jetcache.anno.config.EnableAceMethodCache;
import ace.cmp.spring.data.jdbc.querydsl.core.QuerydslJdbcRepositoryExtendFactoryBean;
import ace.module.oss.core.impl.OssCoreBootstrapScanner;
import ace.module.oss.core.impl.dao.repository.RepositoryScanner;
import ace.module.oss.core.impl.properties.OssCoreProperties;
import org.dromara.x.file.storage.spring.file.MultipartFileWrapperAdapter;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.*;
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
import org.springframework.stereotype.Repository;

/**
* boostrap auto config.
*
* @author Caspar
*/
@EnableAspectJAutoProxy(exposeProxy = true)
@EnableAceMethodCache(basePackageClasses = {OssCoreBootstrapScanner.class})
@EnableConfigurationProperties({OssCoreProperties.class})
@EnableJdbcRepositories(
    basePackageClasses = {RepositoryScanner.class},
    repositoryFactoryBeanClass = QuerydslJdbcRepositoryExtendFactoryBean.class)
@ComponentScan(
    basePackageClasses = OssCoreBootstrapScanner.class,
    excludeFilters = {
      @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Repository.class)
    })
@Configuration
public class OssCoreAutoConfig {
  @ConditionalOnMissingBean
  @Bean
  public MultipartFileWrapperAdapter multipartFileWrapperAdapter() {
    return new MultipartFileWrapperAdapter();
  }
  
  @Bean
  public GroupedOpenApi ossGroupedOpenApi() {
    return GroupedOpenApi.builder()
        .group("oss")
        .displayName("oss服务")
        .packagesToScan(OssCoreBootstrapScanner.class.getPackageName())
        .build();
  }
}
